home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 9
/
FM Towns Free Software Collection 9.iso
/
t_os
/
tool
/
wings
/
w2_src
/
menu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-16
|
15KB
|
562 lines
#include <snd.h>
#include <dos.h>
#include <egb.h>
#include <mos.h>
#include <stdio.h>
#include <conio.h>
#include <direct.h>
#include <stdlib.h>
#include <string.h>
#include "define.h"
#include "extend.h"
#include "module.h"
#include "pd_menu.h"
#include "font_sub.h"
#define CRLF 0xa0d
#define HDE 886
#define MENU_NUMBER 4
extern set_color( void );
extern call_text( char *, char *, int );
extern vsync( void );
extern crtc( char, short );
void text_treatment( int );
void buff_overflow( void );
int call_item( struct PD_menu *, int );
int filer( char *, char *, int, char *, long * );
int filesize;
static char name_entry[16];
static int pdm_adr[ MENU_NUMBER ][ ( ITEM_MAX + 1 ) * 4 ];
static int t_wide = 4;
extern char egbwork[1536], strptn[110592], *buff;
extern char mos_ptn_1[ ], mos_ptn_2[ ], c_dir[ ], EIGHTY;
extern int now_line, max_line, memory, mark[ ], H_SIZE;
extern int offset_address, vram_line, *pointer;
extern int BAR_X, min_position, max_position, scroll_off;
extern UINT k_drv;
extern struct PD_menu menu_buff[ ];
extern int add_ebx[ ], add_edi[ ], tab_wide;
extern int r_line, max_str, l_count_1, l_count_2;
extern char cr_disp;
void menu_function( int menu_x, int menu_y )
{
// メニュー処理
int i, ch, mx, my, max, max_x, max_y, x_size, y_size, pdm_flag[ 6 ];
struct PD_menu *menu;
mos_loop( 2 );
menu = menu_buff;
// ルートメニュー表示位置設定
max = ( max_position + 16 ) - 640;
max_x = 640 - ( ( menu + 0 )->len * 6 + 12 );
max_y = 480 - ( ( menu + 0 )->n * 16 + 8 );
menu_x = ( menu_x>=max_x+max ? max_x+max : menu_x );
menu_y = ( menu_y>=max_y ? max_y : menu_y );
( menu + 0 )->x = menu_x;
( menu + 0 )->y = menu_y;
// ルートメニューの位置によってサブメニューの表示位置を決定する
// 基本的にサブメニューはルートメニューの+16ドットの位置に表示する
// それで画面をはみ出るようなら-16ドットの位置に表示それでも駄目なら
// ぎりぎりの位置に置く
for( i=1;i<=MENU_NUMBER-1;i++ ){
x_size = ( menu + i )->len * 6 + 12;
y_size = ( menu + i )->n * 16 + 8;
max_x = 640 - x_size + max;
max_y = 480 - y_size;
( menu + i )->x
= ( menu_x+16+x_size<=max_position+16 ? menu_x+16 : menu_x-16 );
( menu+i )->y
= ( menu_y+16+y_size<=max_position+16 ? menu_y+16 : menu_y-16 );
if( ( menu + i )->x==menu_x-16 ){
( menu + i )->x
= ( menu_x-16+x_size<=max_position+16 ? menu_x-16 : max_x );
}
if( ( menu + i )->y==menu_y-16 ){
( menu + i )->y
= ( menu_y-16+y_size<=max_position+16 ? menu_y-16 : max_y );
}
}
// 各メニューの各アイテムのアドレスを設定する
PDM_make_item_adress( ( menu + 0 ), pdm_adr[ 0 ] );
PDM_make_item_adress( ( menu + 1 ), pdm_adr[ 1 ] );
PDM_make_item_adress( ( menu + 2 ), pdm_adr[ 2 ] );
PDM_make_item_adress( ( menu + 3 ), pdm_adr[ 3 ] );
// フラグセット
for( i=0;i<=5;i++ )
pdm_flag[ i ] = ON;
if( !now_line ){
pdm_flag[ 1 ] = OFF;
pdm_flag[ 4 ] = OFF;
}
// ルートメニュー表示
MOS_sleep;
EGB_writePage( egbwork, 1 );
PDM_display( egbwork, strptn, ( menu + 0 ), pdm_flag, 0 );
MOS_awake;
while( 6809 ){
do{
MOS_rdpos( &ch, &mx, &my );
} while( !ch );
if( ch==2 ){
MOS_sleep;
PDM_erase( egbwork, menu, 0 );
EGB_writePage( egbwork, 0 );
MOS_awake;
mos_loop( 2 );
return;
}
// マウスの押された位置が有効なら登録されている関数を呼び出す
if( ( i = PDM_get_item_adress( pdm_adr[ 0 ], mx, my ) )!=-1 ){
if( pdm_flag[ i ]==ON ){
( menu + 0 )->item.call_item[ i ]( ( menu + 0 ), i );
return;
}
}
}
}
void draw_center_bar( void ){
// 中央のバーを描く
int x;
x = max_str * 6;
EGB_writePage( egbwork, 0 );
box( egbwork, x, 0, x+1, 511, 7 );
box( egbwork, x+2, 0, x+13, 511, 14 );
box( egbwork, x+14, 0, x+15, 511, 8 );
EGB_writePage( egbwork, 1 );
return;
}
int entry_function_1( struct PD_menu *menu, int n )
{
// 読み込み
char *name, name_buff[16];
int i;
long file_size;
FILE *fp;
PDM_item_clic( egbwork, strptn, menu, n );
name = name_buff;
if( filer( egbwork, strptn, 0, name, &file_size ) ){
PDM_erase( egbwork, menu, 0 );
return( 0 );
}
filesize = ( int )file_size;
if( filesize>memory-256 ){
buff_overflow( );
filesize = memory - 256; // 念のためクッション(256 Bytes)を付けておく
}
MOS_type( 2, 0, 0, mos_ptn_2 );
fp = fopen( name, "rb" );
fread( buff, 1, filesize, fp );
fclose( fp );
strcpy( name_entry, name_buff );
text_treatment( t_wide );
MOS_type( 2, 0, 0, mos_ptn_1 );
// ポインタクリア
for( i=1;i<=5;i++ )
mark[ i ] = 0xffffffff;
// 先頭行と最終行のポインタ設定
mark[ 0 ] = 0;
if( max_line<=80 )
mark[ 6 ] = 0;
else
mark[ 6 ] = max_line - 80;
now_line = 80;
vram_line = 0;
// テキスト表示
set_color( );
offset_address &= 127;
crtc( 17, offset_address );
call_text( strptn, buff, 0 );
draw_center_bar( );
MOS_sleep;
PDM_erase( egbwork, menu, 0 );
MOS_awake;
return( 0 );
}
int entry_function_2( struct PD_menu *menu, int n )
{
// 移動
int i, pdm_flag[ 8 ];
PDM_item_clic( egbwork, strptn, menu, n );
// 移動メニュー表示
for( i=0;i<=7;i++ )
pdm_flag[ i ] = ON;
( menu + 1 )->item.str[ 1 ] = ( mark[ 1 ]==-1 ? "1:未登録" : "1:登録 " );
( menu + 1 )->item.str[ 2 ] = ( mark[ 2 ]==-1 ? "2:未登録" : "2:登録 " );
( menu + 1 )->item.str[ 3 ] = ( mark[ 3 ]==-1 ? "3:未登録" : "3:登録 " );
( menu + 1 )->item.str[ 4 ] = ( mark[ 4 ]==-1 ? "4:未登録" : "4:登録 " );
( menu + 1 )->item.str[ 5 ] = ( mark[ 5 ]==-1 ? "5:未登録" : "5:登録 " );
MOS_sleep;
PDM_display( egbwork, strptn, ( menu + 1 ), pdm_flag, 1 );
MOS_awake;
i = call_item( menu, 1 );
return( i );
}
void entry_jump( struct PD_menu *menu, int n )
{
// 移動処理
int i;
if( !now_line )
return;
if( n==7 ){
for( i=1;i<=5;i++ )
mark[ i ] = 0xffffffff;
}
// マークされていなかったら
else if( mark[ n ]==0xffffffff ){
// 新たに登録
mark[ n ] = now_line - 80;
}
// マークされていたら
else{
// 該当頁を表示
i = mark[ n ];
offset_address &= 127;
crtc( 17, offset_address );
call_text( strptn, buff, i );
draw_center_bar( );
now_line = i + 80;
vram_line = ( now_line - 80 ) * 12;
}
}
int entry_function_3( struct PD_menu *menu, int n )
{
// 書式
int i, pdm_flag[ 4 ];
PDM_item_clic( egbwork, strptn, menu, n );
pdm_flag[ 0 ] = ON;
pdm_flag[ 1 ] = ON;
pdm_flag[ 2 ] = ON;
pdm_flag[ 3 ] = ON;
// 80行表示が選択されていたらが表示域の選択はできなくなるようにする
if( EIGHTY==ON )
pdm_flag[ 2 ] = OFF;
// マークメニュー表示
( menu + 2 )->item.str[ 0 ]
= ( t_wide==4 ? "TAB幅:4" : "TAB幅:8" );
( menu + 2 )->item.str[ 1 ]
= ( cr_disp==ON ? "改行表示:する" : "改行表示:しない" );
( menu + 2 )->item.str[ 2 ]
= ( H_SIZE==640 ? "画面サイズ: 640" : "画面サイズ: 736" );
( menu + 2 )->item.str[ 3 ]
= ( EIGHTY==ON ? "80行表示:する" : "80行表示:しない" );
MOS_sleep;
PDM_display( egbwork, strptn, ( menu + 2 ), pdm_flag, 1 );
MOS_awake;
i = call_item( menu, 2 );
return( i );
}
int entry_tab( struct PD_menu *menu, int n )
{
// タブ変更
int i, *p_ebx, *p_edi, *p_wide;
p_ebx = add_ebx;
p_edi = add_edi;
p_wide = &tab_wide;
t_wide = 12 - t_wide;
for( i=t_wide;i>=1;i-- ){
*( p_ebx + t_wide-i ) = i;
*( p_edi + t_wide-i ) = i*3;
}
*p_wide = t_wide-1;
offset_address &= 127;
crtc( 17, offset_address );
// テキスト整形
MOS_type( 2, 0, 0, mos_ptn_2 );
text_treatment( t_wide );
MOS_type( 2, 0, 0, mos_ptn_1 );
// ポインタクリア
for( i=1;i<=5;i++ )
mark[ i ] = 0xffffffff;
// ポインタ変更
if( max_line<=80 )
mark[ 6 ] = 0;
else
mark[ 6 ] = max_line - 80;
if( max_line<=80 )
now_line = 80;
else if( now_line>max_line )
now_line = max_line;
EGB_writePage( egbwork, 0 );
EGB_color( egbwork, 1, 12 );
EGB_clearScreen( egbwork );
EGB_writePage( egbwork, 1 );
call_text( strptn, buff, now_line - 80 );
draw_center_bar( );
vram_line = ( now_line - 80 ) * 12;
return( 0 );
}
int entry_crlf( struct PD_menu *menu, int n )
{
// 改行表示変更
cr_disp = cr_disp==ON ? OFF : ON;
offset_address &= 127;
crtc( 17, offset_address );
call_text( strptn, buff, now_line - 80 );
draw_center_bar( );
vram_line = ( now_line - 80 ) * 12;
return( 0 );
}
int entry_crtc( struct PD_menu *menu, int n )
{
// 画面サイズ変更
int i, j;
char crtc_adr[ ] = { 0, 1, 4, 29, 9, 18, 10,
11, 22, 12 };
short crtc_dat[ ][ 10 ] = { 96, 704, 799, 2, 778-640, 778-640, 778,
778-640, 778-640, 778,
110, 799, 909, 0, HDE-736, HDE-736, HDE,
HDE-736, HDE-736, HDE };
MOS_sleep;
H_SIZE = ( 736 - H_SIZE ) + 640;
if( H_SIZE==640 ){
max_str = 52;
r_line = 164;
l_count_1 = 39;
l_count_2 = 512-156;
}
else{
max_str = 60;
r_line = 188;
l_count_1 = 45;
l_count_2 = 512-180;
}
j = ( H_SIZE==640 ? 0 : 1 );
// ノイズ対策
vsync( );
for( i=0;i<=9;i++ )
crtc( crtc_adr[ i ], crtc_dat[ j ][ i ] );
// 新しく書き直す
offset_address = 0;
crtc( 17, offset_address );
call_text( strptn, buff, now_line - 80 );
draw_center_bar( );
vram_line = ( now_line - 80 ) * 12;
min_position = 0;
max_position = H_SIZE-16;
MOS_horizon( min_position, max_position );
BAR_X = max_position / 2;
MOS_awake;
return( 0 );
}
int entry_80( struct PD_menu *menu, int n )
{
// 80行表示
EIGHTY = EIGHTY==ON ? OFF : ON;
if( EIGHTY==OFF ){
// 80行表示をやめたときは52行表示に戻る
max_str = 52;
r_line = 164;
l_count_1 = 39;
l_count_2 = 512-156;
crtc( 17, 0 );
crtc( 18, 0x8a );
H_SIZE = 640;
min_position = 0;
max_position = H_SIZE-16;
BAR_X = max_position / 2;
scroll_off = offset_address = 0;
crtc( 17, offset_address );
call_text( strptn, buff, now_line - 80 );
draw_center_bar( );
offset_address = 0;
vram_line = ( now_line - 80 ) * 12;
return( 0 );
}
else{
max_str = 80;
r_line = 248;
l_count_1 = 60;
l_count_2 = 512-240;
crtc( 0, 96 );
crtc( 1, 704 );
crtc( 4, 799 );
crtc( 29, 2 );
crtc( 9, 778-640 );
crtc( 18, 778-640 );
crtc( 10, 778 );
crtc( 11, 778-640 );
crtc( 22, 778-640 );
crtc( 12, 778 );
crtc( 17, 0 );
crtc( 18, 0x8a );
H_SIZE = 976;
min_position = 0;
max_position = 640-16;
MOS_horizon( min_position, max_position );
BAR_X = 960 / 2;
offset_address = 0;
crtc( 17, offset_address );
call_text( strptn, buff, now_line - 80 );
draw_center_bar( );
vram_line = ( now_line - 80 ) * 12;
return( 0 );
}
}
int entry_function_4( struct PD_menu *menu, int n )
{
// 色設定
int i, pdm_flag[ 5 ];
PDM_item_clic( egbwork, strptn, menu, n );
for( i=0;i<=4;i++ )
pdm_flag[ i ] = ON;
// パレットメニュー表示
MOS_sleep;
PDM_display( egbwork, strptn, ( menu + 3 ), pdm_flag, 1 );
MOS_awake;
i = call_item( menu, 3 );
return( i );
}
int entry_palette( struct PD_menu *menu, int n )
{
// 色設定
int pal[ ][ 9 ] = { 1, 0, 0, 2, 2, 8, 11, 8, 14,
2, 12, 2, 5, 3, 5, 14, 12, 14,
12, 4, 12, 14, 14, 14, 0, 8, 6,
0, 15, 4, 10, 15, 12, 7, 7, 7,
12, 0, 8, 15, 15, 15, 1, 0, 0 };
EGB_writePage( egbwork, 0 );
palette( egbwork, 10, pal[n][0]*16, pal[n][1]*16, pal[n][2]*16 );
palette( egbwork, 11, pal[n][3]*16, pal[n][4]*16, pal[n][5]*16 );
palette( egbwork, 12, pal[n][6]*16, pal[n][7]*16, pal[n][8]*16 );
EGB_writePage( egbwork, 1 );
return( 0 );
}
int entry_function_5( struct PD_menu *menu, int n )
{
// 情報
int ch, X;
X = EIGHTY==OFF ? ( H_SIZE - 640 ) / 2 : 0;
PDM_item_clic( egbwork, strptn, menu, n );
MOS_sleep;
getimage( egbwork, 236+X, 150, 236+167+X, 150+83, 1 );
box( egbwork, 236+X, 150, 236+167+X, 150+83, 8 );
box( egbwork, 237+X, 151, 236+164+X, 150+80, 15 );
font_ank_col( 8, 15 );
font_kan_col( 8, 15 );
font_kan( strptn, PAGE_1, POS( 236+12+X, 150+12 ), "ファイル名", 0 );
font_kan( strptn, PAGE_1, POS( 236+12+X, 150+36 ), "現在行", 0 );
font_kan( strptn, PAGE_1, POS( 236+12+X, 150+60 ), "全行数", 0 );
font_mix( strptn, PAGE_1, POS( 236+84+X, 150+12 ), name_entry, 0 );
font_10( strptn, PAGE_1, POS( 236+60+X, 150+36 ), now_line-79, 8, 1 );
font_10( strptn, PAGE_1, POS( 236+60+X, 150+60 ), max_line, 8, 1 );
MOS_awake;
while( 6809 ){
do{
MOS_rdpos( &ch, 0, 0 );
} while( ch!=2 );
mos_loop( 2 );
MOS_sleep;
putimage( egbwork, 236+X, 150, 236+167+X, 150+83, 1 );
PDM_erase( egbwork, menu, 0 );
MOS_awake;
return( 0 );
}
}
int entry_function_6( struct PD_menu *menu, int n )
{
// 終了
int X, ch, mx, my;
PDM_item_clic( egbwork, strptn, menu, n );
MOS_sleep;
X = EIGHTY==OFF ? ( H_SIZE - 640 ) / 2 : 0;
getimage( egbwork, 236+X, 150, 405+X, 215, 1 );
box( egbwork, 236+X, 150, 405+X, 215, 8 );
box( egbwork, 237+X, 151, 402+X, 212, 15 );
font_ank_col( 8, 15 );
font_kan_col( 8, 15 );
font_kan( strptn, PAGE_1, POS( 254+X, 158 ), "Wingsを終了します", 0 );
font_kan( strptn, PAGE_1, POS( 254+X, 192 ), "実行 取消", 0 );
frame( egbwork, 252+X, 190, 279+X, 205, 8 );
frame( egbwork, 250+X, 188, 281+X, 207, 8 );
frame( egbwork, 360+X, 190, 388+X, 205, 8 );
MOS_setpos( ( 405+236+X ) / 2, ( 215+150 ) / 2 );
MOS_awake;
while( 6809 ){
do{
MOS_rdpos( &ch, &mx, &my );
} while( ch!=1 );
if( cmp( mx, 254+X, 277+X ) && cmp( my, 192, 203 ) ){
MOS_sleep;
font_kan_col( 15, 8 );
font_kan( strptn, PAGE_1, POS( 254+X, 192 ), "実行", 0 );
sleep( 10 );
putimage( egbwork, 236+X, 150, 405+X, 215, 1 );
PDM_erase( egbwork, menu, 0 );
MOS_end( );
SND_end( );
free( buff );
free( pointer );
_dos_setdrive( k_drv, 0 );
_chdir( c_dir );
exit( 0 );
}
if( cmp( mx, 362+X, 385+X ) && cmp( my, 192, 203 ) ){
MOS_sleep;
font_kan_col( 15, 8 );
font_kan( strptn, PAGE_1, POS( 362+X, 192 ), "取消", 0 );
mos_loop( 1 );
putimage( egbwork, 236+X, 150, 405+X, 215, 1 );
PDM_erase( egbwork, menu, 0 );
MOS_awake;
return( 0 );
}
}
}
int call_item( struct PD_menu *menu, int n )
{
// マウスの押された位置に登録されている関数を呼び出す
int i, ch, mx, my;
while( 6809 ){
do{
MOS_rdpos( &ch, &mx, &my );
} while( !ch );
if( ch==2 ){
mos_loop( 2 );
MOS_sleep;
PDM_erase( egbwork, ( menu + n ), 1 );
PDM_erase( egbwork, menu, 0 );
MOS_awake;
return( 0 );
}
if( ( i = PDM_get_item_adress( pdm_adr[ n ], mx, my ) )!=-1 ){
PDM_item_clic( egbwork, strptn, ( menu + n ), i );
MOS_sleep;
PDM_erase( egbwork, ( menu + n ), 1 );
PDM_erase( egbwork, menu, 0 );
MOS_awake;
( menu + n )->item.call_item[ i ]( ( menu + n ), i );
return( 0 );
}
}
}